function showPanel(obj) {
    if(obj instanceof jQuery){
        if(obj.attr("id")=="cargo"){
            $("#cargo").css("background-image","linear-gradient(to bottom, white, white)");
            $("#orderForm").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
            $("#personalCenter").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
            $("#cargoPanel").show();
            $("#orderFormPanel").hide();
            $("#personalPanel").hide();
        }
        else if(obj.attr("id")=="orderForm"){
            $("#cargo").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
            $("#orderForm").css("background-image","linear-gradient(to bottom, white, white)");
            $("#personalCenter").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
            $("#cargoPanel").hide();
            $("#orderFormPanel").show();
            $("#personalPanel").hide();
        }
        else if(obj.attr("id")=="personalCenter"){
            $("#cargo").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
            $("#orderForm").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
            $("#personalCenter").css("background-image","linear-gradient(to bottom, white, white)");
            $("#cargoPanel").hide();
            $("#orderFormPanel").hide();
            $("#personalPanel").show();
        }
        // console.log(1)
        // $(".leftElem:hover").css("background-image","linear-gradient(to bottom, red, red)");
        return;
    }
    if($(obj).attr("id")=="cargo"){
        $("#cargo").css("background-image","linear-gradient(to bottom, white, white)");
        $("#orderForm").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
        $("#personalCenter").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
        $("#cargoPanel").show();
        $("#orderFormPanel").hide();
        $("#personalPanel").hide();
    }
    else if($(obj).attr("id")=="orderForm"){
        $("#cargo").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
        $("#orderForm").css("background-image","linear-gradient(to bottom, white, white)");
        $("#personalCenter").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
        $("#cargoPanel").hide();
        $("#orderFormPanel").show();
        $("#personalPanel").hide();
    }
    else if($(obj).attr("id")=="personalCenter"){
        $("#cargo").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
        $("#orderForm").css("background-image","linear-gradient(to bottom, #2AA198, #4DC6AD)");
        $("#personalCenter").css("background-image","linear-gradient(to bottom, white, white)");
        $("#cargoPanel").hide();
        $("#orderFormPanel").hide();
        $("#personalPanel").show();
    }
    // console.log(2);
    // $(".leftElem:hover").css("background-image","linear-gradient(to bottom, red, red)");
    return;
}

$(function () {
    showPanel($("#cargo"));

    // 客服员修改密码
    $(document).on("click", '#wai_modiPwdBtn', function (){

        // 原密码
        var originPwd=$("#wai_modiPwd input[name='wai_oldPwd']").val();
        // 新密码
        var newPwd=$("#wai_modiPwd input[name='wai_newPwd']").val();
        // 确认密码
        var affirmPwd=$("#wai_modiPwd input[name='wai_affirmPwd']").val();

        var func="wai_modiPwdBtn";
        var data={
            'func':func,
            'oldPwd':originPwd,
            'newPwd':newPwd,
            'affirmPwd':affirmPwd
        };
        if(originPwd==""||newPwd==""||affirmPwd=="")
            alert("不允许有空信息被提交。");
        else {
            var account=$("#wai_account").html();
            console.log(account)
            $.ajax({

                url:"/store/waiter/" + account,
                type:'post',
                data:data,
                success: function (data) {
                    if(data['num']==1){
                        // 密码修改成功
                        alert("密码修改成功，请重新登录");
                        location.href="/store/login"
                    }
                    else if(data['num']==-1){
                        // 原密码输入错误
                        $("#wai_error").html("原密码输入错误");
                    }
                    else {
                        // 新密码与确认密码不相符
                        $("#wai_error").html("新密码与确认密码不相符");
                    }
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }
    });

    // 修改基本信息
    $(document).on("click", '#wai_modiBasic', function (){
        var str=$("#wai_modiBasic").html();
        if(str=="修改"){
            $(".basicInfo").removeAttr("disabled");
            $("#wai_modiBasic").html("保存");
        }
        else {
            var account=$("#wai_account").html()
            // 通过ajax传值，修改基本信息
            var accountAlter=$(".info input[name='wai_account']").val();
            var name=$(".info input[name='wai_name']").val();
            console.log(accountAlter);
            console.log(name);
            var data={
                'func':"modiBasicInfo",
                'accountAlter':accountAlter,
                'name':name
            };
            if(accountAlter==""||name=="")
                alert("不允许空值被提交");
            else {
                $.ajax({
                    url: "/store/waiter/" + account,
                    type: 'post',
                    data: data,
                    success: function (data) {
                        console.log(data['num']);
                        if (data['num'] == 0)
                            alert("错误，该账户号已被占用。");
                        else if (data['num'] == 1)
                            alert("基本信息修改成功。");
                        else {
                            alert("基本信息修改成功，请重新登录。");
                            location.href = "/store/login";
                        }
                    },
                    error: function (error) {
                        console.log(error)
                    }
                });
            }
            $(".basicInfo").attr("disabled", "disabled");
            $("#wai_modiBasic").html("修改");
        }
    });

    // 客服员订单信息显示
    $(document).on("click", ':radio', function (){
        if($(this).val()=='notDeal'){
            // console.log($(this).val());
            // 未处理
            var account=$("#wai_account").html()
            $.ajax({
                url:"/store/waiter/" + account,
                type:'post',
                data:{
                    'func':'getNotDealOrderForm'
                },
                success: function (data) {
                    $("#wai_table").html("");
                    var htmlAdd=""
                    // 加表首行
                    htmlAdd+='<tr> <th class="td1">序号</th> <th class="td2">时间</th> <th class="td3">账单描述</th> <th class="td4">总金额</th> <th class="td5">账单状态</th> </tr>'

                    // 将数据显示在每一行中
                    var dataLen=Object.keys(data).length;
                    for(var i=0;i<dataLen;i++){
                        htmlAdd+="<tr><td class='td1'>"+data[i]['no']+"</td><td class='td2'>"+data[i]['date']+"</td><td class='td3'>"+data[i]['desc']+"</td><td class='td4'>"+data[i]['total']+"元</td><td class='td5'>"+data[i]['status']+"</td></tr>"
                    }
                    $("#wai_table").html(htmlAdd);
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }
        else if($(this).val()=='finish'){
            // console.log($(this).val());
            // 已完成
            var account=$("#wai_account").html()
            $.ajax({
                url:"/store/waiter/" + account,
                type:'post',
                data:{
                    'func':'getFinishOrderForm'
                },
                success: function (data) {
                    $("#wai_table").html("");
                    var htmlAdd=""
                    // 加表首行
                    htmlAdd+='<tr> <th class="td1">序号</th> <th class="td2">时间</th> <th class="td3">账单描述</th> <th class="td4">总金额</th> <th class="td5">账单状态</th> </tr>'

                    // 将数据显示在每一行中
                    var dataLen=Object.keys(data).length;
                    for(var i=0;i<dataLen;i++){
                        htmlAdd+="<tr><td class='td1'>"+data[i]['no']+"</td><td class='td2'>"+data[i]['date']+"</td><td class='td3'>"+data[i]['desc']+"</td><td class='td4'>"+data[i]['total']+"元</td><td class='td5'>"+data[i]['status']+"</td></tr>"
                    }
                    $("#wai_table").html(htmlAdd);
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }
        else if($(this).val()=='refund'){
            // 已退费
            // console.log($(this).val());
            var account=$("#wai_account").html()
            $.ajax({
                url:"/store/waiter/" + account,
                type:'post',
                data:{
                    'func':'getRefundOrderForm'
                },
                success: function (data) {
                    $("#wai_table").html("");
                    var htmlAdd=""
                    // 加表首行
                    htmlAdd+='<tr> <th class="td1">序号</th> <th class="td2">时间</th> <th class="td3">账单描述</th> <th class="td4">总金额</th> <th class="td5">账单状态</th> </tr>'

                    // 将数据显示在每一行中
                    var dataLen=Object.keys(data).length;
                    for(var i=0;i<dataLen;i++){
                        htmlAdd+="<tr><td class='td1'>"+data[i]['no']+"</td><td class='td2'>"+data[i]['date']+"</td><td class='td3'>"+data[i]['desc']+"</td><td class='td4'>"+data[i]['total']+"元</td><td class='td5'>"+data[i]['status']+"</td></tr>"
                    }
                    $("#wai_table").html(htmlAdd);
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }
        else {
            // $(this).val()=='all'
            // 全部参与处理的订单
            // 已完成
            // console.log($(this).val());
            var account=$("#wai_account").html()
            $.ajax({
                url:"/store/waiter/" + account,
                type:'post',
                data:{
                    'func':'getAllInvolvedOrderForm'
                },
                success: function (data) {
                    $("#wai_table").html("");
                    var htmlAdd=""
                    // 加表首行
                    htmlAdd+='<tr> <th class="td1">序号</th> <th class="td2">时间</th> <th class="td3">账单描述</th> <th class="td4">总金额</th> <th class="td5">账单状态</th> </tr>'

                    // 将数据显示在每一行中
                    var dataLen=Object.keys(data).length;
                    for(var i=0;i<dataLen;i++){
                        htmlAdd+="<tr><td class='td1'>"+data[i]['no']+"</td><td class='td2'>"+data[i]['date']+"</td><td class='td3'>"+data[i]['desc']+"</td><td class='td4'>"+data[i]['total']+"元</td><td class='td5'>"+data[i]['status']+"</td></tr>"
                    }
                    $("#wai_table").html(htmlAdd);
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }
    });

    // 给td5绑定鼠标移入响应事件
    $(document).on("mouseover", '.td5', function (){
        if($("input[name=sel]:checked").val()=='notDeal'){
            if($(this).html()=="已结算"){
                // console.log("鼠标移入");
                $(this).html("[发货]");
                $(this).css("color",'red');
                $(this).css("text-decoration","underline");
            }
            else if($(this).html()=="已申请退费"){
                $(this).html("[批准退费]");
                $(this).css("color",'red');
                $(this).css("text-decoration","underline");
            }
        }
    });

    // 给td5绑定鼠标移出响应事件
    $(document).on("mouseout", '.td5', function (){
        if($("input[name=sel]:checked").val()=='notDeal'){
            if($(this).html()=="[发货]"){
                // console.log("鼠标移出");
                $(this).html("已结算");
                $(this).css("color",'black');
                $(this).css("text-decoration","");
            }
            else if($(this).html()=="[批准退费]"){
                $(this).html("已申请退费");
                $(this).css("color",'black');
                $(this).css("text-decoration","");
            }
        }
    });

    // 给td5绑定单击响应事件
    $(document).on("click", '.td5', function (){
        if($(this).html()=="[发货]"){
            // 获取订单序号
            var orfo_no=$(this).parent().find(".td1").html()
            // 发货
            var account=$("#wai_account").html()
            $.ajax({
                url:"/store/waiter/" + account,
                type:'post',
                data:{
                    'func':'dealForDeliver',
                    'orfo_no':orfo_no
                },
                success: function (data) {
                    if(data['num']==1) {
                        alert("订单" + orfo_no + "结算成功！");
                        $("#notDealForm").click();
                    }
                    else {
                        //data['num']==0
                        alert("货物不充足，需要补货。");
                    }
                },
                error: function (error) {
                    console.log(error)
                }
            });
        }
        else if($(this).html()=="[批准退费]"){
            // // 获取订单序号
            // var orfo_no=$(this).parent().find(".td1").html()
            // // 批准退费
            // var account=$("#account").html()
            // $.ajax({
            //     url:"/customer/" + account,
            //     type:'post',
            //     data:{
            //         'func':'pay',
            //         'orfo_no':orfo_no
            //     },
            //     success: function (data) {
            //         if(data['num']==0)
            //             alert("您的余额不够。");
            //         else{
            //             alert("订单结算成功。");
            //             location.reload();
            //         }
            //     },
            //     error: function (error) {
            //         console.log(error)
            //     }
            // });
        }
    });

    // 显示所有货物绑定单击响应事件
    $(document).on("click", '#allCargos', function (){
        var account=$("#wai_account").html()
        $.ajax({
            url:"/store/waiter/" + account,
            type:'post',
            data:{
                'func':'getAllCargos'
            },
            success: function (data) {
                $("#wai_cargo_table").html("");
                var htmlAdd=""
                // 加表首行
                htmlAdd+='<tr> <th class="carg_th1">货物号</th> <th class="carg_th2">货物图片</th> <th class="carg_th3">货物描述</th> <th class="carg_th4">制造厂商</th> <th class="carg_th5">货物价格</th><th class="carg_th6">实际存储量</th><th class="carg_th7">最小存储量</th><th class="carg_th8">删除状态</th> </tr>';

                // 将数据显示在每一行中
                var dataLen=Object.keys(data).length;
                for(var i=0;i<dataLen;i++){
                    htmlAdd+='<tr> <td class="carg_td1">'+data[i]['no']+'</td> <td class="carg_td2">'+data[i]['photo']+'</td> <td class="carg_td3">'+data[i]['desc']+'</td> <td class="carg_td4">'+data[i]['manu']+'</td> <td class="carg_td5">'+data[i]['price']+'元</td><td class="carg_td6">'+data[i]['stock']+'</td><td class="carg_td7">'+data[i]['minStock']+'</td><td class="carg_td8">'+data[i]['delStatus']+'</td> </tr>';
                }
                $("#wai_cargo_table").html(htmlAdd);
            },
            error: function (error) {
                console.log(error)
            }
        });
    });

    // 显示未删除货物绑定单击响应事件
    $(document).on("click", '#notDelCargos', function (){
        var account=$("#wai_account").html()
        $.ajax({
            url:"/store/waiter/" + account,
            type:'post',
            data:{
                'func':'getNotDelCargos'
            },
            success: function (data) {
                $("#wai_cargo_table").html("");
                var htmlAdd=""
                // 加表首行
                htmlAdd+='<tr> <th class="carg_th1">货物号</th> <th class="carg_th2">货物图片</th> <th class="carg_th3">货物描述</th> <th class="carg_th4">制造厂商</th> <th class="carg_th5">货物价格</th><th class="carg_th6">实际存储量</th><th class="carg_th7">最小存储量</th><th class="carg_th8">删除状态</th> </tr>';

                // 将数据显示在每一行中
                var dataLen=Object.keys(data).length;
                for(var i=0;i<dataLen;i++){
                    htmlAdd+='<tr> <td class="carg_td1">'+data[i]['no']+'</td> <td class="carg_td2">'+data[i]['photo']+'</td> <td class="carg_td3">'+data[i]['desc']+'</td> <td class="carg_td4">'+data[i]['manu']+'</td> <td class="carg_td5">'+data[i]['price']+'元</td><td class="carg_td6">'+data[i]['stock']+'</td><td class="carg_td7">'+data[i]['minStock']+'</td><td class="carg_td8">'+data[i]['delStatus']+'</td> </tr>';
                }
                $("#wai_cargo_table").html(htmlAdd);
            },
            error: function (error) {
                console.log(error)
            }
        });
    });

    // 显示已删除货物绑定单击响应事件
    $(document).on("click", '#delCargos', function (){
        var account=$("#wai_account").html()
        $.ajax({
            url:"/store/waiter/" + account,
            type:'post',
            data:{
                'func':'getDelCargos'
            },
            success: function (data) {
                $("#wai_cargo_table").html("");
                var htmlAdd=""
                // 加表首行
                htmlAdd+='<tr> <th class="carg_th1">货物号</th> <th class="carg_th2">货物图片</th> <th class="carg_th3">货物描述</th> <th class="carg_th4">制造厂商</th> <th class="carg_th5">货物价格</th><th class="carg_th6">实际存储量</th><th class="carg_th7">最小存储量</th><th class="carg_th8">删除状态</th> </tr>';

                // 将数据显示在每一行中
                var dataLen=Object.keys(data).length;
                for(var i=0;i<dataLen;i++){
                    htmlAdd+='<tr> <td class="carg_td1">'+data[i]['no']+'</td> <td class="carg_td2">'+data[i]['photo']+'</td> <td class="carg_td3">'+data[i]['desc']+'</td> <td class="carg_td4">'+data[i]['manu']+'</td> <td class="carg_td5">'+data[i]['price']+'元</td><td class="carg_td6">'+data[i]['stock']+'</td><td class="carg_td7">'+data[i]['minStock']+'</td><td class="carg_td8">'+data[i]['delStatus']+'</td> </tr>';
                }
                $("#wai_cargo_table").html(htmlAdd);
            },
            error: function (error) {
                console.log(error)
            }
        });
    });

    // 给carg_td8绑定鼠标移入响应事件
    $(document).on("mouseover", '.carg_td8', function (){
        if($(this).html()=="未删除"){
            // console.log("鼠标移入");
            $(this).html("[删除]");
            $(this).css("color",'red');
            $(this).css("text-decoration","underline");
        }
    });

    // 给carg_td8绑定鼠标移出响应事件
    $(document).on("mouseout", '.carg_td8', function (){
        if($(this).html()=="[删除]"){
            // console.log("鼠标移入");
            $(this).html("未删除");
            $(this).css("color",'black');
            $(this).css("text-decoration","");
        }
    });

    // 给carg_td8绑定单击响应事件
    $(document).on("click", '.carg_td8', function (){
        if($(this).html()=="[删除]") {
            // 获取货物号
            var carg_no = $(this).parent().find(".carg_td1").html()
            var flag=confirm("是否确定删除货物"+carg_no+"？");

            if(flag==true) {
                var account = $("#wai_account").html()
                $.ajax({
                    url: "/store/waiter/" + account,
                    type: 'post',
                    data: {
                        'func': 'deleteCargo',
                        'carg_no': carg_no
                    },
                    success: function (data) {
                        if (data['num'] == 1) {
                            alert("货物" + carg_no + "删除成功！");
                            $("#allCargos").click();
                        }
                    },
                    error: function (error) {
                        console.log(error)
                    }
                });
            }else{
                alert("您已取消删除货物"+carg_no+"。");
            }
        }
    });
});